<?php
/**
 *
 * @authors generator
 * @date    2020-10-16 11:33:35
 */

namespace App\Commons\Domain\Module\UserCenter\Model;

use App\Commons\Domain\Casts\Ip;
use App\Commons\Domain\Core\Model;
use App\Commons\Domain\Module\UserCenter\Model\Admin;
use App\Commons\Domain\Module\UserCenter\Model\Member;
use Illuminate\Auth\Authenticatable;
use Illuminate\Contracts\Auth\Access\Authorizable as AuthorizableContract;
use Illuminate\Contracts\Auth\Authenticatable as AuthenticatableContract;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Foundation\Auth\Access\Authorizable;

/**
 * App\Commons\Domain\Module\UserCenter\Model\Account
 *
 * @property int $id
 * @property \Illuminate\Support\Carbon $created_at
 * @property \Illuminate\Support\Carbon $updated_at
 * @property string $uid
 * @property string $username 登录名
 * @property string $mobile 手机号
 * @property string $email 邮箱
 * @property string $password 密码
 * @property \Illuminate\Support\Carbon|null $last_logined_at 最后登录时间
 * @property array $last_logined_ip 最后登录ip
 * @property int $logined_count 登录次数
 * @property-read Member $member
 * @method static \Illuminate\Database\Eloquent\Builder|Account newModelQuery()
 * @method static \Illuminate\Database\Eloquent\Builder|Account newQuery()
 * @method static \Illuminate\Database\Eloquent\Builder|Account query()
 * @method static \Illuminate\Database\Eloquent\Builder|Account whereCreatedAt($value)
 * @method static \Illuminate\Database\Eloquent\Builder|Account whereEmail($value)
 * @method static \Illuminate\Database\Eloquent\Builder|Account whereId($value)
 * @method static \Illuminate\Database\Eloquent\Builder|Account whereLastLoginedAt($value)
 * @method static \Illuminate\Database\Eloquent\Builder|Account whereLastLoginedIp($value)
 * @method static \Illuminate\Database\Eloquent\Builder|Account whereLoginedCount($value)
 * @method static \Illuminate\Database\Eloquent\Builder|Account whereMobile($value)
 * @method static \Illuminate\Database\Eloquent\Builder|Account wherePassword($value)
 * @method static \Illuminate\Database\Eloquent\Builder|Account whereUid($value)
 * @method static \Illuminate\Database\Eloquent\Builder|Account whereUpdatedAt($value)
 * @method static \Illuminate\Database\Eloquent\Builder|Account whereUsername($value)
 * @mixin \Eloquent
 * @property-read Admin $admin
 */
class Account extends Model implements
    AuthorizableContract,
    AuthenticatableContract
{
    use Authenticatable, Authorizable;
    use HasFactory;
    protected $hidden = ['id', 'uid', 'password'];

    protected $dates = ['last_logined_at'];
    protected $casts = [
        'last_logined_ip' => Ip::class
    ];
    // protected $fillable = ['phone', 'password', 'status','name'];

    /**
     * Get the name of the unique identifier for the user.
     *
     * @return string
     */
    public function getAuthIdentifierName()
    {
        return 'uid';
    }


    public function member()
    {
        return $this->belongsTo(Member::class, 'uid', 'uid');
    }

    public function admin()
    {
        return $this->belongsTo(Admin::class, 'uid', 'uid');
    }
}
